package com.yhc.my.an_meishia.utils;

import com.yhc.my.an_meishia.bean.Beans;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/13.
 */
public class ParseJSON {

    public static List<Beans> parseJSONResult(String json){
        List<Beans> list = new ArrayList<>();
        try {
            JSONArray arr = new JSONArray(json);
            for (int i = 0; i < arr.length(); i++) {
                JSONObject obj = arr.getJSONObject(i);
                String id = obj.getString("id");
                String type = obj.getString("type");
                String name = obj.getString("name");
                Beans beans = new Beans(id,type,name);
                list.add(beans);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
